﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TimberSmart.Model;
using TimberSmart.Model.Business;
using TimberSmart.Model.Common;
using TimberSmart.Model.Security;

namespace TimberSmart.Data.TestData
{
    //public class TimberSmartDatabaseInitializer : DropCreateDatabaseIfModelChanges<TimberSmartDbContext>
    public class TimberSmartDatabaseInitializer : DropCreateDatabaseAlways<TimberSmartDbContext>
    {

        protected override void Seed(TimberSmartDbContext context)
        {
            // Seeding default data.
            // Whenever a table is dropped and recreated, it will be loaded with these values.


            //context.Customers.Add(new Customer()
            //{
            //    CompanyName = "TimberSmart",
            //    Address = new Address()
            //    {
            //        Address1 = "address one",
            //        Address2 = "address two",
            //        Suburb = "suburb",
            //        State = "state",
            //        PostCode = 2134
            //    }
            //});

            Menu m1 = new Menu() { DisplayName = "Inventory", InternalName = "Inventory 1", Description = "Desc." };
            Menu m2 = new Menu() { DisplayName = "Debtors", InternalName = "Debtors 1", Description = "Desc2." };

            Menu m3 = new Menu() { DisplayName = "Customers", InternalName = "Customers 1", Description = "Desc3." };

            Role r1 = new Role() { Name = "Administrators" };


            User u1 = new User()
            {
                FirstName = "Joel",
                LastName = "Warburton",
                Username = "Joel",
                PasswordHash = Encoding.UTF8.GetBytes("PasswordHash"),
                PasswordSalt = Encoding.UTF8.GetBytes("PasswordSalt"),
                Email = "joelw@timbersmart.com.au",
                Title = "Mr.",
                Description = "Tits"
            };

            User u2 = new User()
            {
                FirstName = "Greg",
                LastName = "Middleton",
                Username = "Greg",
                PasswordHash = Encoding.UTF8.GetBytes("PasswordHash"),
                PasswordSalt = Encoding.UTF8.GetBytes("PasswordSalt"),
                Email = "gregm@timbersmart.com.au",
                Title = "Mrs.",
                Description = "Mansawce"
            };


            r1.Menus = new List<Menu>();

            u1.Roles = new List<Role>();
            u2.Roles = new List<Role>();

            m1.Children = new List<Menu>();

            context.Users.Add(u1);
            context.Users.Add(u2);

            r1.Menus.Add(m1);
            r1.Menus.Add(m2);
            r1.Menus.Add(m3);

            m1.Children.Add(m3);

            u1.Roles.Add(r1);
            u2.Roles.Add(r1);

            context.SaveChanges();
        }
    }
}
